package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.hr.dto.ApplyToProgLevelAddDTO;
import org.jsola.hr.dto.ApplyToProgLevelUpdateDTO;
import org.jsola.hr.entity.ApplyToProgLevelDO;
import org.jsola.hr.query.ApplyToProgLevelQuery;
import org.jsola.hr.service.IApplyToProgLevelService;
import org.jsola.hr.vo.ApplyToProgLevelVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class ApplyToProgLevelTestHelper extends BaseTestHelper {
    
    @Autowired
    private IApplyToProgLevelService applyToProgLevelService;

    /**
     * 生成add测试数据
     * @return ApplyToProgLevelAddDTO
     */
    public ApplyToProgLevelAddDTO getApplyToProgLevelAddDTO(){
        ApplyToProgLevelAddDTO applyToProgLevelAddDTO = new ApplyToProgLevelAddDTO();
        applyToProgLevelAddDTO.setProgId(getRandomValue("varchar",32));
        applyToProgLevelAddDTO.setLevelId(getRandomValue("varchar",32));
        applyToProgLevelAddDTO.setCompanyId(getRandomValue("varchar",32));
        return applyToProgLevelAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ApplyToProgLevelUpdateDTO
     */
    public ApplyToProgLevelUpdateDTO getApplyToProgLevelUpdateDTO(ApplyToProgLevelVO applyToProgLevelVO){
        return applyToProgLevelService.selectDOById(applyToProgLevelVO.getId(), SITE_ID).to(ApplyToProgLevelUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ApplyToProgLevelQuery
     */
    public ApplyToProgLevelQuery getApplyToProgLevelQuery() {
        ApplyToProgLevelQuery applyToProgLevelQuery = new ApplyToProgLevelQuery();
        List<ApplyToProgLevelDO> applyToProgLevelDOList = applyToProgLevelService.list(new ApplyToProgLevelDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(applyToProgLevelDOList)) {
            ApplyToProgLevelDO applyToProgLevelDO = applyToProgLevelDOList.get(0);
            applyToProgLevelQuery = applyToProgLevelDO.to(ApplyToProgLevelQuery.class);
            if (applyToProgLevelDO.getGmtCreate() != null) {
                applyToProgLevelQuery.setGmtCreateStart(DateKit.getBeforeDay(applyToProgLevelDO.getGmtCreate(),-1));
                applyToProgLevelQuery.setGmtCreateEnd(DateKit.getBeforeDay(applyToProgLevelDO.getGmtCreate(),1));
            }
        }
        return applyToProgLevelQuery;
    }

    /**
     * 保存示例
     * @return ApplyToProgLevelVO
     */
    public ApplyToProgLevelVO saveApplyToProgLevelExample(){
        ApplyToProgLevelAddDTO addDTO = this.getApplyToProgLevelAddDTO();
        ApplyToProgLevelVO applyToProgLevelVO = applyToProgLevelService.save(addDTO,buildTokenUser());
        return applyToProgLevelVO;
    }


}

